<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello, World</title>
    <style type="text/css">
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #container{width: 500px;
            height: 500px;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=DEHpNMjbGQWQzxu0uYGtqdhzX8gq8hGy">
        //v2.0版本的引用方式：src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"
    </script>
</head>

<body>
<div id="container"></div>
<script type="text/javascript">
    /*var map = new BMap.Map("container");
    // 创建地图实例
    var point = new BMap.Point(116.404, 39.915);
    // 创建点坐标
    map.centerAndZoom(point, 15);*/
    // 初始化地图，设置中心点坐标和地图级别

    var map = new BMap.Map("container", {enableMapClick:false});
    var point = new BMap.Point(116.331398,39.897445);
    map.centerAndZoom(point,12);
    map.addControl(new BMap.NavigationControl());
    map.addControl(new BMap.ScaleControl());
    map.addControl(new BMap.OverviewMapControl());

    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            var mk = new BMap.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            // alert('您的位置：'+r.point.lng+','+r.point.lat);
        }
        else {
            alert('failed'+this.getStatus());
        }
    });
    map.enableScrollWheelZoom();
    map.addEventListener("click", function(e){
        console.log(e);

        var allOverlay = map.getOverlays();

        for(var i = 0;i<allOverlay.length;i++) {
            if(allOverlay[i].toString()=="[object Marker]"){
                map.removeOverlay(allOverlay[i]);
            }
        }
        var marker = new BMap.Marker(e.point);
        // point = new BMap.Point(e.point.lat, e.point.lng);
        map.addOverlay(marker);
        }
    );
</script>
</body>
</html>